﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DB;
using System.Data.SqlClient;


namespace Control
{
    public class MovieController
    {
        DbMovie dbMovie;
        public MovieController()
        {
            dbMovie = new DbMovie();
        }

        public void CreateMovie(string serialNo,string length, string title, string genre, DateTime releaseDate, double ranking)
        {
            try
            {
                Movie newMovie = new Movie(serialNo, length, title, genre, releaseDate, ranking);

                dbMovie.InsertMovie(newMovie);
            }
            catch (Exception ex)
            {

                Console.WriteLine("Ctrl Caught: " + ex.Message);
            }
                
            

        }

        public void DeleteMovie(string serialNo)
        {

            Movie newMovie = new Movie(serialNo);
            try
            {
                dbMovie.DeleteMovie(newMovie);
            }
            catch (SqlException sqle)
            {
                Console.WriteLine("HELLLLLLLLOOOO");
                Console.WriteLine(sqle.Message);
                throw sqle;
            }
            catch (Exception e)
            {
                Console.WriteLine("HELLLLLLLLOOOO");
                Console.WriteLine(e.Message);
                throw e;
            }
        }

        public List<Movie> FindAllMovies()
        {
            return dbMovie.FindAllMovies();
        }

        public Movie FindMovie(string serialNo)
        {
            return dbMovie.FindMovie(serialNo);
        }


        
    }
}
